/*
 * Copyright (c) 2001-2007, TIBCO Software Inc.
 * Use, modification, and distribution subject to terms of license.
 */

jsx3.require("jsx3.gui.Button");

/**
 * Provides a object-oriented interface for a button for use in a pipe. To be used ONLY in a ux.megatron.gui.Pipe object.
 * <p/>
 * This class publishes the following model events:
 * <ul>
 * <li><code>EXECUTE</code> - when the user clicks on the enabled button, when the button has focus and the user presses the
 *    space or enter key, or when <code>doExecute()</code> is called on the button.</li>
 * <li><code>MENU</code> - on a mouseup event with the right button when the button has a bound context menu.</li>
 * </ul>
 */
jsx3.Class.defineClass("ux.megatron.gui.PipeButton", jsx3.gui.Button, null, function(Button, Button_prototype) {

    Button.unpressedBG = null;

    Button_prototype.init = function(strName, intLeft, intTop, intWidth, strText) {
        //call constructor for super class
        this.jsxsuper(strName, intLeft, intTop, intWidth, strText);
    };

    Button.getUnpressedBG = function() {
        if(!this.unpressedBG) {
            this.unpressedBG = "background-image: url(" + ux.megatron.Main.getServer().resolveURI("jsxaddin://user!Megatron/images/matrix/pipeButton.jpg") + "); background-repeat: repeat; cursor: pointer";
        }
        return this.unpressedBG;
    }

    Button.getPressedBG = function() {
        if(!this.pressedBG) {
            this.pressedBG = "background-image: url(" + ux.megatron.Main.getServer().resolveURI("jsxaddin://user!Megatron/images/matrix/pipeButton_selected.jpg") + "); background-repeat: repeat; cursor: default";
        }
        return this.pressedBG;
    }

    Button_prototype.doPressed = function(objEvent) {
        this.setCSSOverride(Button.getPressedBG());
        this.repaint();
    }

    Button_prototype.doUnpressed = function() {
            this.setCSSOverride(Button.getUnpressedBG());
            this.repaint();
    }

    Button_prototype.onSetParent = function(parent) {
        try {
            this.setCSSOverride(Button.getUnpressedBG());
            this.repaint();
        } catch(ex) {
            ux.megatron.Main.logException(ex);
        }
        return this.jsxsuper(parent);
    }

});
